﻿using MediatR;
using Traceability.App.Apilication.Common.Breeding;
using Traceability.App.Domain;
using Traceability.ErrorCode;
using Traceability.Infrastructure.Interfance;

namespace Traceability.App.Apilication.Handler.Breeding
{
    public class InquireBreedingHandler : IRequestHandler<InquireBreedingCommon, ApiResult<List<BreedingModel>>>
    {
        private readonly IBaseRespository<BreedingModel> breedingRepo;

        public InquireBreedingHandler(IBaseRespository<BreedingModel> breedingRepo)
        {
            this.breedingRepo = breedingRepo;
        }
        public Task<ApiResult<List<BreedingModel>>> Handle(InquireBreedingCommon request, CancellationToken cancellationToken)
        {
            ApiResult<List<BreedingModel>> res = new ApiResult<List<BreedingModel>>();

            var info = breedingRepo.GetAll().Where(x=>x.Production_Batch==request.Production_Batch).ToList();

            res.Code = ApiEnum.Success;
            res.Message = "通过生产批次查询养殖信息";
            res.Data = info;
            return Task.FromResult(res);

        }
    }
}
